from typing import Optional
import decimal

from sqlalchemy import BigInteger, DECIMAL, Integer, String
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column

class Base(DeclarativeBase):
    pass


class BsKline(Base):
    __tablename__ = 'bs_kline'

    id: Mapped[int] = mapped_column(Integer, primary_key=True)
    date: Mapped[int] = mapped_column(BigInteger, nullable=False, comment='交易所行情日期')
    code: Mapped[str] = mapped_column(String(255), nullable=False, comment='证券代码')
    open: Mapped[Optional[decimal.Decimal]] = mapped_column(DECIMAL(50, 6), comment='开盘价')
    high: Mapped[Optional[decimal.Decimal]] = mapped_column(DECIMAL(50, 6), comment='最高价')
    low: Mapped[Optional[decimal.Decimal]] = mapped_column(DECIMAL(50, 6), comment='最低价')
    close: Mapped[Optional[decimal.Decimal]] = mapped_column(DECIMAL(50, 6), comment='收盘价')
    preclose: Mapped[Optional[decimal.Decimal]] = mapped_column(DECIMAL(50, 6), comment='前收盘价')
    volume: Mapped[Optional[decimal.Decimal]] = mapped_column(DECIMAL(50, 6), comment='成交量（累计 单位：股）')
    amount: Mapped[Optional[decimal.Decimal]] = mapped_column(DECIMAL(50, 6), comment='成交额（单位：人民币元）')
    adjustflag: Mapped[Optional[int]] = mapped_column(Integer, comment='复权状态(1：后复权， 2：前复权，3：不复权）')
    turn: Mapped[Optional[decimal.Decimal]] = mapped_column(DECIMAL(50, 6), comment='换手率([指定交易日的成交量(股)/指定交易日的股票的流通股总股数(股)]*100%)')
    tradestatus: Mapped[Optional[int]] = mapped_column(Integer, comment='交易状态(1：正常交易 0：停牌）')
    pctChg: Mapped[Optional[decimal.Decimal]] = mapped_column(DECIMAL(50, 6), comment='涨跌幅（百分比）(日涨跌幅=[(指定交易日的收盘价-指定交易日前收盘价)/指定交易日前收盘价]*100%)')
    peTTM: Mapped[Optional[decimal.Decimal]] = mapped_column(DECIMAL(50, 6), comment='滚动市盈率(指定交易日的股票收盘价/指定交易日的每股盈余TTM)=(指定交易日的股票收盘价*截至当日公司总股本)/归属母公司股东净利润TTM')
    pbMRQ: Mapped[Optional[decimal.Decimal]] = mapped_column(DECIMAL(50, 6), comment='市净率(指定交易日的股票收盘价/指定交易日的每股净资产)=总市值/(最近披露的归属母公司股东的权益-其他权益工具)')
    psTTM: Mapped[Optional[decimal.Decimal]] = mapped_column(DECIMAL(50, 6), comment='滚动市销率(指定交易日的股票收盘价/指定交易日的每股销售额)=(指定交易日的股票收盘价*截至当日公司总股本)/营业总收入TTM')
    pcfNcfTTM: Mapped[Optional[decimal.Decimal]] = mapped_column(DECIMAL(50, 6), comment='滚动市现率(指定交易日的股票收盘价/指定交易日的每股现金流TTM)=(指定交易日的股票收盘价*截至当日公司总股本)/现金以及现金等价物净增加额TTM')
    isST: Mapped[Optional[int]] = mapped_column(Integer, comment='是否ST股，1是，0否')
